//
//  HomeViewController.m
//  ELibary
//
//  Created by luoz on 15/8/10.
//  Copyright (c) 2015年 luoz. All rights reserved.
//

#import "HomeViewController.h"
#import "DataManager+CreateTable.h"
#import <Quartz/Quartz.h>

@interface HomeViewController ()

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do view setup here.
    
    BOOL isSuccess = [[DataManager shareManager] createItemsTable];
    if(isSuccess){
        NSLog(@"success");
    }
}

- (IBAction)stepperChange:(id)sender {
    
    NSStepper *stepper = sender;
    
    self.textFieldNumberContent.stringValue = stepper.stringValue;
    
}

- (IBAction)buttonSelectImageClicked:(id)sender {
    
    IKPictureTaker *pictureTaker = [IKPictureTaker pictureTaker];
    
    /* set default image */
    //[self setImageInputForPictureTaker:pictureTaker];
    
    /* configure the PictureTaker to show effects */
    [pictureTaker setValue:[NSNumber numberWithBool:YES] forKey:IKPictureTakerShowEffectsKey];
    
    /* launch the PictureTaker as a panel */
    [pictureTaker beginPictureTakerWithDelegate:self didEndSelector:@selector(pictureTakerValidated:code:contextInfo:) contextInfo:nil];
}

#pragma mark -
#pragma mark delegate

// -------------------------------------------------------------------------
//	pictureTakerValidated:code:contextInfo:
//
//  Invoked when the PictureTaker terminates.
//	Retrieves the output image and sets it on the view
// -------------------------------------------------------------------------
- (void) pictureTakerValidated:(IKPictureTaker*) pictureTaker code:(int) returnCode contextInfo:(void*) ctxInf
{
    if(returnCode == NSOKButton){
        /* retrieve the output image */
        NSImage *outputImage = [pictureTaker outputImage];
        
        self.imageViewIcon.image = outputImage;
        /* change the displayed image */
        //[imageView setImage:outputImage];
    }
    else{
        /* the user canceled => nothing to do here */
    }
}


@end
